package com.franklin.java.completion.map;

import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;

import java.util.Objects;

/**
 * @author Franklin
 * @since 2021/8/6 18:47
 */
public class MapDeclaration {

    private PsiElement declareStatement;
    private String keyType;
    private String valeType;
    private boolean isMethodCall = false;
    private String declareLast;
    private boolean isClassField = false;
    private String assignKey;
    private String assignValue;
    private boolean isParent = false;
    private boolean isCollection = false;

    private MapDeclaration child;

    public MapDeclaration(PsiElement declareStatement, String keyType, String valeType) {
        this.declareStatement = declareStatement;
        this.keyType = keyType;
        this.valeType = valeType;
        this.isMethodCall = declareStatement instanceof PsiMethodCallExpression;
        PsiMethod psiMethod = PsiTreeUtil.getParentOfType(declareStatement, PsiMethod.class);
        this.isClassField = Objects.isNull(psiMethod);
    }

    public MapDeclaration(PsiElement declareStatement, String keyType, String valeType,String declareLast) {
        this(declareStatement, keyType, valeType);
        this.declareLast = declareLast;
    }

    public boolean isClassField() {
        boolean isClassField = this.isClassField;
        this.isClassField = false;
        return isClassField;
    }

    public boolean isCollection() {
        return isCollection;
    }

    public void setCollection() {
        isCollection = true;
    }

    public MapDeclaration getChild() {
        return child;
    }

    public String getAssignValue() {
        return assignValue;
    }

    public void setAssignValue(String assignValue) {
        this.assignValue = assignValue;
    }

    public void setChild(MapDeclaration child) {
        this.child = child;
    }

    public boolean isParent() {
        return isParent;
    }

    public void setParent(boolean parent) {
        isParent = parent;
    }

    public String getAssignKey() {
        return assignKey;
    }

    public void setAssignKey(String assignKey) {
        this.assignKey = assignKey;
    }

    public boolean isMethodCall() {
        return isMethodCall;
    }

    public PsiElement getDeclareStatement() {
        return declareStatement;
    }

    public String getKeyType() {
        return keyType;
    }

    public String getValeType() {
        return valeType;
    }

    public String getDeclareLast() {
        return declareLast;
    }
}
